<template>
  <div id="app">
    <w-p-d-f
      v-if="pofUrl"
      @error="error"
      :url="pofUrl"/>
  </div>
</template>

<script>

  export default {
    name: 'App',
    metaInfo: {
      meta: [
        { name: 'viewport', content: 'width=device-width, initial-scale=1.0,minimum-scale=1.0, maximum-scale=1.0,user-scalable=no' }
      ]
    },
    components: {
      WPDF: resolve => { require(['../../components/global/PDF'], resolve) }
    },
    data(){
      return {
        pofUrl: null
      }
    },
    methods: {
      getQueryStringArgs(url) {
        url = url == null ? window.location.href : url;
        const qs = url.substring(url.lastIndexOf("?") + 1);
        const args = {};
        const items = qs.length > 0 ? qs.split('&') : [];
        let item = null;
        let name = null;
        let value = null;
        for (var i = 0; i < items.length; i++) {
          item = items[i].split("=");
          //用decodeURIComponent()分别解码name 和value（因为查询字符串应该是被编码过的）。
          name = decodeURIComponent(item[0]);
          value = decodeURIComponent(item[1]);
          if (name.length) {
            args[name] = value;
          }
        }
        return args;
      },
      error() {
        this.pofUrl = 'https://cdn.wangyabin.top/Extension/pdf/web/404.pdf'
      }
    },
    mounted() {
      this.pofUrl = this.getQueryStringArgs().file
    }
  }
</script>
<style>
</style>
